package com.ucampus.controller;

import com.ucampus.entity.oS_views;
import com.ucampus.service.oS_viewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 功能：
 * 作者： 启明星_Polaris
 * 日期：2025/1/6 下午8:30
 **/

@RestController
@RequestMapping("/views")
public class oS_viewsController {

    @Autowired
    private oS_viewsService viewsService;

    @GetMapping("/page")
    public ResponseEntity<List<oS_views>> getAllViews(@RequestParam("page") int page, @RequestParam(value = "size", defaultValue = "7") int size) {
        {
            List<oS_views> views = viewsService.getAllViews(page, size);
            return views != null && !views.isEmpty() ? ResponseEntity.ok(views) : ResponseEntity.notFound().build();
        }
    }

    @GetMapping("/details")
    public ResponseEntity<oS_views> getViewsById(@RequestParam("viewsId") int id) {
        oS_views view = viewsService.getInfoById(id);
        return view != null ? ResponseEntity.ok(view) : ResponseEntity.notFound().build();
    }
}
